from selenium import webdriver
import time
import os
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
url = "file:///"+os.path.abspath("C:\\课件\\我的课件\\测试\\selenium2/locateElement/selenium2html/alert.html")
driver.get(url)
driver.maximize_window()
time.sleep(3)

# 定位元素，点击，使得弹出框出现
driver.find_element_by_id("tooltip").click()
time.sleep(3)
# 定位弹出框/获得弹出框的操作句柄
alert = driver.switch_to.alert
time.sleep(3)
# 关闭alert
alert.accept()
time.sleep(5)
driver.quit()

